using ns0;
using ns4;
using ns6;
using System;
using System.IO;
using System.Windows.Media.Imaging;
namespace MicroMsg.UI.Util
{
	public class BarCodeMakerUtil
	{
		public static WriteableBitmap MakeBarCode(string strContent)
		{
			QRCodeWriter qRCodeWriter = new QRCodeWriter();
			ByteMatrix byteMatrix_ = qRCodeWriter.encode(strContent, BarcodeFormat.QR_CODE, 440, 440);
			return BarCodeMakerUtil.createImgFromMatrix(byteMatrix_);
		}
		public static MemoryStream GetStreamFromBitmap(WriteableBitmap writeableBitmap_0)
		{
			if (writeableBitmap_0 == null)
			{
				return null;
			}
			MemoryStream memoryStream = new MemoryStream();
			Extensions.SaveJpeg(writeableBitmap_0, memoryStream, writeableBitmap_0.get_PixelWidth(), writeableBitmap_0.get_PixelHeight(), 0, 100);
			return memoryStream;
		}
		private static WriteableBitmap createImgFromMatrix(ByteMatrix byteMatrix_0)
		{
			if (byteMatrix_0 == null)
			{
				return null;
			}
			WriteableBitmap writeableBitmap = new WriteableBitmap(byteMatrix_0.get_Width(), byteMatrix_0.get_Height());
			for (int i = 0; i < byteMatrix_0.get_Height(); i++)
			{
				for (int j = 0; j < byteMatrix_0.get_Width(); j++)
				{
					if (-1 == byteMatrix_0.get_Array()[i][j])
					{
						writeableBitmap.get_Pixels()[i * byteMatrix_0.get_Width() + j] = -1;
					}
					else
					{
						writeableBitmap.get_Pixels()[i * byteMatrix_0.get_Width() + j] = 0;
					}
				}
			}
			return writeableBitmap;
		}
	}
}
